




//index.js
//获取应用实例
const app = getApp()
var p=app.globalData.rootPath
var openid=app.globalData.openid
var c=require("../common.js")
Page({
  data: {
 slide:[
 ],
    curit:1,
    jigou:null
  },
  onLoad: function () {
    wx.showLoading({
      title: '加载中...',
    })
// ********************************************************************以下复制粘贴就行
    //调用微信支付api先生成预支付订单

    // wx.request({
    //   url: 'http://xwz.wyuek.com/Wxpay/example/jsapi.php',
    //   data: {
    //     openId: wx.getStorageSync("openid"),
    //     money: 0.01
    //   },
    //   success: function (response) {

    //     var miyao = response.data.miyao;
    //     var lghtime = response.data.lghtime
    //     var appId = response.data.appid;
    //     var timeStamp = (Date.parse(new Date()) / 1000).toString();
    //     var pkg = 'prepay_id=' + response.data.prepay_id;
    //     var payid = response.data.prepay_id;
    //     var nonceStr = response.data.nonce_str;
    //     var md5 = require('../../utils/md5.js');
    //     var paySign = md5.hex_md5('appId=' + appId + '&nonceStr=' + nonceStr + '&package=' + pkg + '&signType=MD5&timeStamp=' + timeStamp + "&key=" + miyao).toUpperCase();

    //     wx.requestPayment({
    //       'timeStamp': timeStamp,
    //       'nonceStr': nonceStr,
    //       'package': pkg,
    //       'signType': 'MD5',
    //       'paySign': paySign,
    //       'success': function (res) {
    //         if (res.errMsg == "requestPayment:ok") {
    //           //todo支付成功之后的逻辑问题

    //         } else {
    //           //tode支付失败之后逻辑问题
    //         }
    //       },
    //       'fail': function (res) {
    //         wx.showToast({
    //           title: '支付失败',
    //           icon: 'loading',
    //           duration: 10000,
    //           mask: true
    //         })
    //         setTimeout(function () {
    //           wx.hideLoading()
    //         }, 1000)
    //       }
    //     });
    //   },
    //   header: {
    //     'content-type': 'application/x-www-form-urlencoded'
    //   },
    // });
// ********************************************************************以下复制粘贴就行
    //判断是否登录
   var userInfo=wx.getStorageSync("userInfo")||[]



   if(userInfo.length==0){
     wx.redirectTo({
       url: '/pages/login/index',
     })
     return false
   }
   //加载轮播图
   c.ajax(
     app.globalData.rootPath+"/index.php/index/Wxapi/getslide",
     {},
     res=>{
       this.setData({
         slide:res.data
       })
     },
     function(res){

     }
   )
   //加载顶部菜单并将第一个菜单的店铺列出来
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/gettopcate",
     {},
     res => {
       this.setData({
         topcate: res.data
       })
     }
   )
   //加载推荐课程
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/gettuijiangoods",
     {},
     res => {
       this.setData({
         tuijian: res.data
       })
     }
   )
   //加载文化教育课程
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getwenhuajiaoyu",
     {},
     res => {
       this.setData({
         wenhuajiaoyu: res.data
       })
     }
   )
   //加载文化教育下级分类
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getwenhuajiaoyutwocate",
     {},
     res => {
       this.setData({
         wenhuajiaoyutwocate: res.data
       })
     }
   )
   //加载语言学习课程
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getyuyanxuexi",
     {},
     res => {
       this.setData({
         yuyanxuexi: res.data
       })
     }
   )
   //加载语言学习下级分类
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getyuyanxuexitwocate",
     {},
     res => {
       this.setData({
         yuyanxuexitwocate: res.data
       })
     }
   )
   //加载办公效率课程
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getbangongxiaolv",
     {},
     res => {
       this.setData({
         bangongxiaolv: res.data
       })
     }
   )
   //加载办公效率下级分类
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getbangongxiaolvtwocate",
     {},
     res => {
       this.setData({
         bangongxiaolvtwocate: res.data
       })
     }
   )
   //加载职业发展课程
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getzhiyefazhan",
     {},
     res => {
       this.setData({
         zhiyefazhan: res.data
       })
     }
   )
   //加载职业发展下级分类
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getzhiyefazhantwocate",
     {},
     res => {
       this.setData({
         zhiyefazhantwocate: res.data
       })
     }
   )
   //加载产品研发课程
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getchanpinkaifa",
     {},
     res => {
       this.setData({
         chanpinkaifa: res.data
       })
     }
   )
    //加载产品研发课程展会
    c.ajax(
      app.globalData.rootPath + "/index.php/index/Wxapi/getchanpinkaifaahznhui",
      {},
      res => {
        this.setData({
          chanpinkaifazhanhui: res.data
        })
      }
    )
   //加载产品研发下级分类
   c.ajax(
     app.globalData.rootPath + "/index.php/index/Wxapi/getchanpinkaifatwocate",
     {},
     res => {
       this.setData({
         chanpinkaifatwocate: res.data
       })
     }
   )
    //加载热门机构
    c.ajax(
      app.globalData.rootPath + "/index.php/index/Wxapi/hotjigou",
      {},
      res => {
        this.setData({
          jigou: res.data
        })
      }
    )
   setTimeout(() => { wx.hideLoading()},500)

  },
  toviewlog(){
    wx.navigateTo({
      url: '../viewlog/index',
    })
  },
  totopcate(e){
    wx.navigateTo({
      url: '../topcate/index?flaginfo=' + e.currentTarget.dataset.flaginfo,
    })
  },
  toxuanke(e){
    wx.navigateTo({
      url: '../xuanke/index?flaginfo=' + e.currentTarget.dataset.flaginfo + '&cate_id=' + e.currentTarget.dataset.cate_id,
    })
  },
  toactivity(){
    wx.navigateTo({
      url: '../activity/index',
    })
  },
  tonewslist(){
    wx.navigateTo({
      url: '../newslist/index',
    })
  },
  clickfonttopninfo:function(e){
    var curit=e.currentTarget.dataset.curit;
    this.setData({ curit: curit});
  },
  gotop:function(){
    wx.pageScrollTo({
      scrollTop: 0,
    })
  },
  inDetail:function(e){
    // 商品类型：

    // 1 -> 一对一直播
    // 2 -> 单节视频
    // 3 -> 套课
    // 4 -> 套课中的视频
    // 5 -> 预约直播
    // 6 -> 一对多直播
    var gid=e.currentTarget.dataset.goodsid;
    var sql = 'w(goods_id=' + gid+')f(type)l(1)';
    c.ajax(
      app.dbs+'goods',
      { sql: sql},
      res=>{
       var typeinfo= res.data.type;
        console.log(typeinfo);
        if (typeinfo==2){
            wx.navigateTo({
              url: '/pages/detailsdanke/detailsdanke?goods_id=' + gid,
            })
        } else if (typeinfo == 3){
          wx.navigateTo({
            url: '/pages/detailtaoke/detailtaoke?goods_id=' + gid,
          })
        } else if (typeinfo == 1 || typeinfo == 6){
          wx.navigateTo({
            url: '/pages/detailzhibo/detailzhibo?goods_id=' + gid,
          })
        } 
      }
    )
  },
  inputclick:function(){
    wx.navigateTo({
      url: '/pages/search/search',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  mywantren:function(){
    var user_id = wx.getStorageSync("userInfo").user_id;
    c.ajax(
      app.url + 'zizhistatus',
      { user_id: user_id },
      res => {
        if (res.data != 101) {
          // 通过
          if (res.data == 1) {
            wx.navigateTo({
              url: '/pages/myzizhipass/myzizhipass',
            })
            //未通过
          } else if (res.data == 2) {
            wx.navigateTo({
              url: '/pages/myzizhierror/myzizhierror',
            })
            //审核
          } else {
            wx.navigateTo({
              url: '/pages/myzizhiing/myzizhiing',
            })
          }
        } else {
          wx.navigateTo({
            url: '/pages/myzizhi/myzizhi',
          })
        }
      }
    ) 
  }
})
